/*
 * Copyright (c) 2017, www.zm0618.com All Rights Reserved..
 */

package com.light.hessian.remoting.client.xml;

import com.light.hessian.remoting.client.balance.Balance;
import com.light.hessian.provider.discovery.DiscoveryType;
import com.light.hessian.provider.discovery.ProviderAutoDiscoverer;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.w3c.dom.Element;

/**
 * Created by zhaojun on 2017/02/09.
 */
public class ProviderAutoDiscovererBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {

    @Override
    protected Class<?> getBeanClass(Element element) {
        return ProviderAutoDiscoverer.class;
    }

    @Override
    protected void doParse(Element element, BeanDefinitionBuilder builder) {
        String provider = element.getAttribute("provider");
        String protocol=element.getAttribute("protocol");
        String autoDiscovery=element.getAttribute("autoDiscovery");
        String discoveryType=element.getAttribute("type");
        String registryConf=element.getAttribute("config");
        String balance=element.getAttribute("balance");

        builder.addPropertyValue("provider",provider);
        builder.addPropertyValue("protocol",protocol);
        builder.addPropertyValue("autoDiscovery",Boolean.valueOf(autoDiscovery));
        builder.addPropertyValue("discoveryType",Enum.valueOf(DiscoveryType.class,discoveryType));
        builder.addPropertyValue("registryConf",registryConf);
        builder.addPropertyValue("balance",Enum.valueOf(Balance.class,balance));

    }


    @Override
    protected boolean shouldGenerateId() {
        return false;
    }
}
